----------------------------------------------------------------------------------------------------------------------------------------------------
--[[
    【坤乾否卦帽】是帽子，不会变潮湿，戴在头上只会提供70雨露值/min。刚转变时【霉运】值为777点，【霉运】降为0时转变为【乾坤泰卦帽】。
【坤乾否卦帽】每秒减少0.49点【霉运】，在夏天或是附近7距离内有热源（篝火，营火，龙蝇火炉）时，每秒额外减少【霉运】0.49点。
【坤乾否卦帽】没有存储格子，但可以放入特定物品作为“燃料”。每放入一个【蝙蝠翅膀】减少【霉运】7点，每放入一个【蝙蝠棒】减少【霉运】49点。
]]--
----------------------------------------------------------------------------------------------------------------------------------------------------
---
    local assets =
    {
        Asset("ANIM", "anim/cane.zip"),
        Asset("ANIM", "anim/swap_cane.zip"),
    }
----------------------------------------------------------------------------------------------------------------------------------------------------
--- 穿脱
    local function onequip(inst, owner)

    end

    local function onunequip(inst, owner)

    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- hook equipable
    local function equipable_IsRestricted(equipable_com,target)
        --return true if restricted (can't equip)
        if target:HasTag("hutao") then 
            local replica = equipable_com.inst.replica.hutao_com_cosmic_hat_sys_for_item or equipable_com.inst.replica._.hutao_com_cosmic_hat_sys_for_item              
            if replica and replica:GetLinkedPlayer() == target then
                return false
            else
                print("error : hat replica miss")
            end
        end
        return true
    end
    local function hook_equipable(inst,replica_com)
        replica_com.IsRestricted = equipable_IsRestricted
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- 霉运系统
    local function bad_luck_sys_install(inst)
        local fn_table = require("prefabs/06_equipments/05_04_cosmic_hat_bad_luck")
        local fn = fn_table and fn_table.ground or nil
        if type(fn) == "function" then
            fn(inst)
        end
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- 转换控制
    local function tran_2_another_hat(inst)
        local fn_table = require("prefabs/06_equipments/05_05_cosmic_hat_transfrom")
        local fn = fn_table and fn_table.ground or nil
        if type(fn) == "function" then
            fn(inst)
        end
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- 
    local function ground_special_fn(inst)
        local fn = require("prefabs/06_equipments/06_02_cosmic_hat_ground_logic")
        if type(fn) == "function" then
            fn(inst)
        end
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- 本体
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddSoundEmitter()
        inst.entity:AddNetwork()

        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank("cane")
        inst.AnimState:SetBuild("swap_cane")
        inst.AnimState:PlayAnimation("idle")

        inst:AddTag("irreplaceable")
        inst:AddTag("nonpotatable")
        inst:AddTag("ground")

        local swap_data = {sym_build = "swap_cane"}
        MakeInventoryFloatable(inst, "med", 0.05, {0.85, 0.45, 0.85}, true, 1, swap_data)


        inst.entity:SetPristine()
        -----------------------------------------------------
        --- 
            tran_2_another_hat(inst)
            ground_special_fn(inst)
        -----------------------------------------------------
        --- 
            inst:ListenForEvent("HUTAO_OnEntityReplicated.equippable",hook_equipable)
        -----------------------------------------------------
        if not TheWorld.ismastersim then
            return inst
        end
        -----------------------------------------------------
        --- 保鲜控制器
            inst:AddComponent("preserver")
        -----------------------------------------------------
        --- 防水
            inst:AddTag("waterproofer")            
            inst:AddComponent("waterproofer")
            inst.components.waterproofer:SetEffectiveness(0)
        -----------------------------------------------------
        --- 
            inst:AddComponent("hutao_com_cosmic_hat_sys_for_item")
            inst.components.hutao_com_cosmic_hat_sys_for_item:SetMax(777.7)
            bad_luck_sys_install(inst)
        -----------------------------------------------------
        --- 调用梅花的冷热源
            inst:AddComponent("hutao_com_flower_switcher")
            inst.components.hutao_com_flower_switcher:SetIsFlower(false)
        -----------------------------------------------------
        --- 
            inst:AddComponent("named")
            inst:AddComponent("inspectable")
            inst:AddComponent("inventoryitem")
            inst.components.inventoryitem:ChangeImageName("tophat")
            -- inst.components.inventoryitem.imagename = "hutao_cooked_food_excample"
            -- inst.components.inventoryitem.atlasname = "images/inventoryimages/hutao_cooked_food_excample.xml"
        -----------------------------------------------------
        --- 穿戴
            inst:AddComponent("equippable")
            inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
            inst.components.equippable:SetOnEquip(onequip)
            inst.components.equippable:SetOnUnequip(onunequip)
        -----------------------------------------------------
            MakeHauntableLaunch(inst)
        -----------------------------------------------------
        return inst
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
return Prefab("hutao_equipment_cosmic_hat_ground", fn, assets)
